const app = getApp()
var api = require('../../../utils/networkApi.js');
var commonMethod = require("../../../utils/commonMethod.js"); 


Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    max: 150, //限制最大输入字符数
    surplusWordNumber: 150, //剩余字数
    orderItem:[],//已接单 异常申请 点击的对象
    remarks:"",
    orderClickPosition:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      orderItem: JSON.parse(options.orderItem),
      orderClickPosition: options.orderClickPosition
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  /****限制字数与计算 */
  getValueLength: function(e) {
    let value = commonMethod.filterEmoji(e.detail.value);
    
    let len = parseInt(value.length)
    debugger
    //最多字数限制
    if (len > this.data.max) return;
    let num = (this.data.max - len);
    this.setData({
      surplusWordNumber: num //剩余字数 
    })

    this.setData({
      remarks: value
    })
  
  },
  //提交
  submitAbnormal: function (e) {

    if (commonMethod.filterSpace(this.data.remarks)== "") {
      wx.showToast({
        title: '请输入内容',
        icon: 'none'
      })
      return;
    }
   
    var dataBody = {
      "trustOrderNo": this.data.orderItem.trustOrderNo,
      "orderNo": this.data.orderItem.wpOrderInfoResponse.orderUuid, 
      "ladingNo": this.data.orderItem.wpOrderInfoResponse.ladingNo, 
      "remarks": this.data.remarks,
      "version": this.data.orderItem.version
    }
    api.networkForData("applyForException", dataBody)
      .then(res => {
        wx.redirectTo({
          url: '/pages/orderManager/abnormalApplicationSuccess/abnormalApplicationSuccess?orderClickPosition=' + this.data.orderClickPosition + '&version=' + this.data.orderItem.version,
        })
      })

    
  }
})